//
//  AddGroupChatCell.m
//  PigMarket
//
//  Created by mac on 2019/6/17.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AddGroupChatCell.h"

@interface AddGroupChatCell ()
/**
 头像
 */
@property (nonatomic , strong) UIImageView *headerImg;
/**
 昵称
 */
@property (nonatomic , strong) UILabel *nameLab;
/**
 个性签名
 */
@property (nonatomic , strong) UILabel *detailLab;
/**
 选中icon
 */
@property (nonatomic , strong) UIImageView *selectIcon;
/**
 灰线
 */
@property (nonatomic , strong) UIView *hLine;

@end
@implementation AddGroupChatCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifierID = @"identifierID";
    AddGroupChatCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[AddGroupChatCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
#pragma mark - init method
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.selectIcon];
    [self.contentView addSubview:self.headerImg];
    [self.contentView addSubview:self.nameLab];
    [self.contentView addSubview:self.detailLab];
    [self.contentView addSubview:self.hLine];
    [self.contentView addSubview:self.unableSelectView];
}

- (void)initLayout {
    // 布局子控件
    [self.selectIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(22, 22));
    }];
    [self.headerImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.selectIcon.mas_right).offset(15);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headerImg.mas_right).offset(20);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(22);
        make.right.mas_equalTo(-10);
    }];
    [self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLab.mas_left);
        make.top.mas_equalTo(self.nameLab.mas_bottom).offset(6);
        make.height.mas_equalTo(19);
        make.right.mas_equalTo(-15);
    }];
    [self.hLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.detailLab.mas_left);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.right.mas_equalTo(0);
    }];
    [self.unableSelectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
}

#pragma mark - getter and setter
- (void)setFriendListModel:(Friends *)friendListModel {
    _friendListModel = friendListModel;
    self.headerImg.image = friendListModel.headImage;
//    [self.headerImg sd_setImageWithURL:[NSURL URLWithString:friendListModel.headImg ? friendListModel.headImg : @""] placeholderImage:[UIImage imageNamed:@"placeholder_header"]];
    NSString *name = friendListModel.noteName ? friendListModel.noteName : friendListModel.nickName;
    self.nameLab.text = name;
    self.detailLab.text = friendListModel.personality;
    if (friendListModel.isSelect) {
        self.selectIcon.image = [UIImage imageNamed:@"pay_default_selected"];
    } else {
        self.selectIcon.image = [UIImage imageNamed:@"pay_default"];
    }
}

- (UIImageView *)selectIcon {
    if (!_selectIcon) {
        _selectIcon = [[UIImageView alloc] init];
        _selectIcon.image = [UIImage imageNamed:@"pay_default"];
    }
    return _selectIcon;
}
- (UIImageView *)headerImg {
    if (!_headerImg) {
        _headerImg = [[UIImageView alloc] init];
        _headerImg.layer.cornerRadius = 25;
        _headerImg.layer.masksToBounds = YES;
        _headerImg.backgroundColor = [UIColor randomColor];
    }
    return _headerImg;
}
- (UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.textColor = [UIColor textBlackColor];
        _nameLab.font = [UIFont largerFont];
    }
    return _nameLab;
}

- (UILabel *)detailLab {
    if (!_detailLab) {
        _detailLab = [[UILabel alloc] init];
        _detailLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _detailLab.font = [UIFont middleFont];
    }
    return _detailLab;
}
- (UIView *)hLine {
    if ((!_hLine)) {
        _hLine = [[UIView alloc] init];
        _hLine.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.08];
    }
    return _hLine;
}
- (UIView *)unableSelectView {
    if ((!_unableSelectView)) {
        _unableSelectView = [[UIView alloc] init];
        _unableSelectView.backgroundColor = [UIColor colorWithHexString:@"#ffffff" alpha:0.5];
        _unableSelectView.hidden = YES;
    }
    return _unableSelectView;
}
@end
